import {Pipe,PipeTransform} from '@angular/core';

// Tell Angular2 we're creating a Pipe with TypeScript decorators
@Pipe({
  name: 'hidePhonePipe',
})
export class HidePhonePipe implements PipeTransform{

  // Transform is the new "return function(value, args)" in Angular 1.x
  transform(value, args?) {  
    if(!value){
      console.log("value");
    }else{
      if(value.length > 11){
        var reg = /^(\S*)(\S{4})(\S{4})$/;
        return  value.replace(reg, "$1****$3");
      }
      else if(value.length == 11){
        let reg = /^(\S{3})(\S{4})(\S{4})$/;
        return  value.replace(reg, "$1****$3");
      }
      else if(value.length > 4){
        var reg = /^(\S*)(\S{4})$/;
        return  value.replace(reg, "****$2");
      }else{
        var reg = /^(\S*)(\S{1})$/;
        return  value.replace(reg, "**$2");
      }
    }
    
    
  }

}